﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class BonusLog : IValidatableObject, IAggregateRoot
    {
        public int LogID { get; set; }

        [Required(ErrorMessage="请选择正确的用户")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的用户编号！")]
        public int UserID { get; set; }

        [Required(ErrorMessage = "请选择正确的活动")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的活动编号！")]
        public int PartyID { get; set; }

        [RegularExpression(@"^(-?\d+)(\.\d+)?$", ErrorMessage = "请输入正确的积分值！")]
        public Nullable<decimal> Bonus { get; set; }

        public string Desc { get; set; }

        public DateTime CreateDate { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (UserID < 0)
            {
                yield return new ValidationResult("用户不能为空!");
            }

            if (PartyID < 0)
            {
                yield return new ValidationResult("活动不允许为空！");
            }

        }
    }
}
